
var time_,img_show,img_add='';
addcontent = function(data,obj,postid){
	for(var key in data.content) {
		time_ = data.content[key].time.substring(0,10);
		for(var x = 0;x<6;x++){
			if(data.pic[x] == "undefined" || data.pic[x] == undefined) {
				continue;
			}else{
				img_show = '<img src="' + data.pic[x] + '" alt="">';
				img_add += img_show;
			}
		}
		////console.log("img_add"+img_add);
		var dom = '<li class="mui-media">' +
				'<div class="this_Title">' +
				'<img id="firsthead" class="circle mui-media-object mui-pull-left round" id="pic1" src="'+data.content[key].headurl+'">' +
				'<div class="mui-media-body body_position">' +
				'<h5 id="firstauthor"></h5>' +
				'<p id="firsttime" class="mui-ellipsis">'+data.username.username+'<span>'+time_+'</span></p>' +
					//'<div class="Concern">关注</div>' +
				'</div>' +
				'</div>' +
				'<div class="mui-media-body this_content">' +
				'<h4 id="firsttitle">'+data.content[key].title+'</h4>' +
				'<div class="content_img"></div>' +
				'<p class="content_text">'+data.content[key].content+'</p>' +
				'<p class="content_text">'+img_add+'</p>' +
				'</div>' +
				'<div class="del">' +
				'<span id="del">删除本帖</span>' +
				'</div>' +
				'</li>';
		$(obj).append(dom);
		img_add = '';
		img_show = "";
	}

	//个人删帖
	document.getElementById('del').addEventListener('tap', function () {
		if (mui.os.plus) {
			var a = [{
				title: "删帖"
			}];
			plus.nativeUI.actionSheet({
				title: "是否删除本帖",
				cancel: "取消",
				buttons: a
			}, function (b) { /*actionSheet 按钮点击事件*/
				switch (b.index) {
					case 0:
						break;
					case 1:
						delete_tie();
						break;
					default:
						break;
				}
			})
		}
	}, false);

	mui.ajax(getFindNameByid, {
		data: {
			"flag": postid
		},
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型
		timeout: 10000, //超时时间设置为10秒；
		success: function(data) {
			////console.log(JSON.stringify(data));
			$("#firstauthor").text(data.name);
		}
	});
}


addcomment = function(data,obj) {
	for(var key in data.comment) {
		time_ = data.comment[key].time.substring(0,10);
		//var dom = '<li class="mui-table-view-cell mui-media">\
		//		<a href="javascript:;">\
		//			<img id="replyhead" class="circle mui-media-object mui-pull-left round" id="pic1" src="'+data.comment[key].headurl+'">\
		//			<div class="mui-media-body">\
		//				<h5 id="replyauthor">'+data.comment[key].username+'</h5>\
		//				<p id="replytime" class="mui-ellipsis">'+data.comment[key].time+'</p>\
		//			</div>\
		//			<div class="mui-media-body">\
		//				<h5 id="replycontent">'+data.comment[key].content+'</h5>\
		//			</div>\
		//		</a>\
		//	</li>';
		var dom = '<li class="mui-table-view-cell mui-media">' +
				'<a href="javascript:;">' +
				'<div class="this_Title">' +
				'<img id="huifuhead" class="circle mui-media-object mui-pull-left round" id="pic2" src="'+data.comment[key].headurl+'">' +
				'<div class="mui-media-body">' +
				'<h5 id="huifuauthor">'+data.comment[key].username+'<span></span></h5>' +
				'<p id="huifutitle" class="mui-ellipsis show_content">'+data.comment[key].content+'</p>' +
				'<p id="huifutime" class="mui-ellipsis">第<b></b>楼<span>'+time_+'</span></p>' +
				'</div>' +
				'</div>' +
				'</a>' +
				'</li>';
		$(obj).append(dom);
	}
}


gotoerror = function() {

	var dom = '<div style="text-align:center;margin-top:30px;color:grey;"> \
						帖子加载中...请下拉刷新\
					</div>';
	$("#spread").append(dom);

}


function delete_tie() {
	var self = plus.webview.currentWebview();
	var postid = self.postid,location_ad;
	var postid_text = postid.substring(0, 1);
		mui.ajax(delete_three, {
			data: {
				"id": tie_id,
				"token":lget("token")
			},
			dataType: 'json',//服务器返回json格式数据
			type: 'post',//HTTP请求类型
			timeout: 10000,//超时时间设置为10秒；
			success: function (data) {
				//						//console.log(JSON.stringify(data.code))
				if (data.code == 1) {
					mui.toast("删帖成功");
					var gotofind = plus.webview.getWebviewById("sub_find_tieba.html");
					mui.fire(gotofind,'reloadList');
					mui.back();
				} else {
					mui.toast("非本人不能删帖");
				}
				mui.back();
			},
			error: function (xhr, type, errorThrown) {

				mui.toast('网络连接失败');
			}
		});
}